package study.saas.web.portal.sys.admin;

import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import study.saas.common.util.viewmodel.ApiResultV2;
import study.saas.order.entity.Commodity;
import study.saas.order.service.CommodityFacade;
import study.saas.order.service.model.*;


/**
 * @author wwy
 */
@Api(tags = "商品管理")
@RestController
@RequestMapping(value = "sys/commodity")
public class CommodityController {

    @Reference(version = "1.0.0")
    private CommodityFacade commodityFacade;

    @ApiOperation(value = "查找")
    @RequestMapping(value = "/find",method = RequestMethod.GET)
    public ApiResultV2<Commodity> findCommodity(String commodityName) {
        if (commodityName == null ) {
            return ApiResultV2.error("数据不能为空！");
        }

        return commodityFacade.findCommodity(commodityName);
    }


    @ApiOperation(value = "添加")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ApiResultV2 addCommodity(CommodityAddDTO add) {
        if (add == null) {
            return ApiResultV2.error("数据不能为空!");
        }
        return commodityFacade.addCommodity(add);
    }

    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ApiResultV2<Commodity> deleteCommodity(String commodityName){
        if(commodityName ==null){
            return ApiResultV2.error("数据不能为空！");
        }
        return commodityFacade.deleteCommodity(commodityName);
    }

    @ApiOperation(value = "修改")
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public ApiResultV2 modifyCommodity(CommodityModifyDTO modify) {
        if (modify == null) {
            return ApiResultV2.error("数据不能为空！");
        }
        return commodityFacade.modifyCommodity(modify);
    }


    @ApiOperation(value = "修改")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiResultV2 listCommodity(CommodityFilterDTO filter) {
        if (filter == null) {
            return ApiResultV2.error("数据不能为空！");
        }
        return commodityFacade.listCommodity(filter);
    }





}
